﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Caching;
using System.IO;
using BullTasDesaDal.Entities;
using BullTasDesaDal.Service;



namespace WSBulTasDesa
{
    public class CachingHelper
    {
        
        
        public static IList<Province> LoadProvinces()
        {

            ObjectCache cache = MemoryCache.Default;
            IList<Province> lprovinces = cache["provinces"] as IList<Province>;
            if (lprovinces == null)
            {
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
                lprovinces = LocationService.GetAllProvinces().ToList();
                cache.Set("provinces", lprovinces, policy);
            }
            return lprovinces;

        }

        public static IList<Region> LoadRegions()
        {

            ObjectCache cache = MemoryCache.Default;
            IList<Region> lregions = cache["regions"] as IList<Region>;
            if (lregions == null)
            {
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
                lregions = RegionService.GetAll().ToList();
                cache.Set("regions", lregions, policy);
            }
            return lregions;

        }

        public static IList<Revisor> LoadRevisors()
        {

            ObjectCache cache = MemoryCache.Default;
            IList<Revisor> lrevisors = cache["revisors"] as IList<Revisor>;
            if (lrevisors == null)
            {
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(12);
                lrevisors = AppraisalService.GetAllRevisors().ToList();
                cache.Set("revisors", lrevisors, policy);
            }
            return lrevisors;

        }

    }
}